package com.Maykk.StudentManager;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @ClassName: StuPage
 * @Description: TODO 视图层
 * @Author: MaykkStar@163.com
 */
public class StuPage {
    private StuPage() {
    }

    /**
     * 欢迎页面
     *
     * @return 选择的功能
     */
    public static int welcome() {
        System.out.println("+++++++++++++");
        System.out.println("+ 1.查询学员 +");
        System.out.println("+ 2.添加学员 +");
        System.out.println("+ 3.修改学员 +");
        System.out.println("+ 4.删除学员 +");
        System.out.println("+ 0.退出系统 +");
        System.out.println("+++++++++++++");
        int choose;
        do {
            System.out.println("请选择功能：");
            choose = new Scanner(System.in).nextInt();
        } while (choose < 0 || choose > 4);
        return choose;
    }

    /**
     * 查询菜单二级页面
     *
     * @return 用户功能选择
     */
    public static int fingShow() {
        System.out.println("* *********** *");
        System.out.println("* 查询功能选择页面");
        System.out.println("* 1 - 查询全部");
        System.out.println("* 2 - 按学号查询");
        System.out.println("* 3 - 按姓名查询");
        System.out.println("* 4 - 按性别查询");
        System.out.println("* 5 - 按年龄查询");
        System.out.println("* 6 - 按成绩查询");
        System.out.println("* 0 - 返回主菜单");
        System.out.println("* *********** *");
        int c;
        do {
            System.out.println("请选择功能：");
            c = new Scanner(System.in).nextInt();
        } while (c < 0 || c > 6);
        return c;
    }

    /**
     * 显示学员信息格式（多个）
     *
     * @param stuList 学员信息 （集合）
     */
    public static void showStuList(ArrayList<Student> stuList) {

        System.out.printf("┌──────┬────────────┬──────┬──────┬──────┐\n");
        System.out.printf("│%-6s│%-12s│%-6s│%-6s│%-6s│\n", "ID", "NAME", "SEX", "AGE", "SCORE");
        for (Student stulist : stuList) {
            System.out.printf("├──────┼────────────┼──────┼──────┼──────┤\n");
            System.out.printf("│%-6d│%-10s│%-6s│%-6d│%-6.1f│\n", stulist.getId(), stulist.getName(), stulist.getSex(), stulist.getAge(), stulist.getScore());
        }
        System.out.print("└──────┴────────────┴──────┴──────┴──────┘\n");
    }

    public static int inputID() {
        System.out.print("请输入要查询的学员ID: ");
        return new Scanner(System.in).nextInt();
    }

    public static String inputName() {
        System.out.print("请输入要查询的学员姓名: ");
        return new Scanner(System.in).nextLine();
    }

    public static String inputSex() {
        System.out.print("请输入要查询的学员性别: ");
        return new Scanner(System.in).nextLine();
    }

    public static int inputAge() {
        System.out.print("请输入要查询的学员年龄: ");
        return new Scanner(System.in).nextInt();
    }

    public static float inputScore() {
        System.out.println("请输入要查询的学员成绩: ");
        return new Scanner(System.in).nextFloat();
    }

    public static int inputDelID() {
        System.out.println("请输入要删除的学员ID");
        return new Scanner(System.in).nextInt();
    }

    /**
     * 添加学员
     *
     * @return 返回为 null 时表示结束添加，返回 Student 类时添加学员
     */
    public static Student getAddStu() {
        System.out.print("请输入要添加的学员姓名: ");
        String stuName = new Scanner(System.in).nextLine();
        if (stuName.equals("over"))
            return null;
        System.out.print("请输入要添加的学员性别: ");
        String stuSex = new Scanner(System.in).next();
        System.out.print("请输入要添加的学员年龄: ");
        int stuAge = new Scanner(System.in).nextInt();
        System.out.print("请输入要添加的学员成绩: ");
        float stuScore = new Scanner(System.in).nextFloat();
        return new Student(stuName, stuSex, stuAge, stuScore);
    }

    /**
     * 确认操作
     *
     * @return 键入 Y 返回 true, 键入 N 返回 false,输入错误返回 false
     */
    public static boolean AreYouOK() {
        System.out.println("是否删除此学员？~\nY.删除\nN.返回");
        switch (new Scanner(System.in).next()) {
            case "Y":
            case "y":
                return true;
            case "N":
            case "n":
                return false;
            default:
                System.out.println("输入错误，将返回菜单！~");
                break;
        }
        return false;
    }

    /**
     * 返回错误信息
     *
     * @param s 要输出的错误信息
     */
    public static void failed(String s) {
        System.out.println(s);
    }

    /**
     * 编辑查找到的学员信息
     *
     * @param serchID 要编辑的学员的 ID
     * @return 编辑后的学员信息对象
     */
    public static Student editStu(ArrayList<Student> serchID) {
        System.out.println("请输入学员（" + serchID.get(0).getName() + "）姓名");
        String stuName = new Scanner(System.in).nextLine();

        System.out.println("请输入学员（" + serchID.get(0).getName() + "）性别");
        String stuSex = new Scanner(System.in).next();

        System.out.println("请输入学员（" + serchID.get(0).getName() + "）年龄");
        int stuAge = new Scanner(System.in).nextInt();

        System.out.println("请输入学员（" + serchID.get(0).getName() + "）成绩");
        float stuScore = new Scanner(System.in).nextFloat();
        return new Student(serchID.get(0).getId(), stuName, stuSex, stuAge, stuScore);
    }
}
